package cn.edu.csust.coursecard.controller;

import cn.edu.csust.coursecard.annotation.RequiredAdmin;
import cn.edu.csust.coursecard.dao.entity.MuteVo;
import cn.edu.csust.coursecard.common.ReturnData;
import cn.edu.csust.coursecard.dao.dto.MuteInfo;
import cn.edu.csust.coursecard.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 许大人
 */
@RestController
public class AdminController {

    @Autowired
    AdminService adminService;

    @PostMapping("/adminLogin")
    public ReturnData login(String username,String password){
        return adminService.login(username, password);
    }

    /**
     * 禁言
     */
    @PostMapping("/mute")
    @RequiredAdmin
    public ReturnData mute(@RequestBody MuteVo muteVo){
        return adminService.mute(muteVo.getUserId(),muteVo.getMuteDay());
    }
    
    /**
     * 禁言
     */
    @PostMapping("/cancelMute")
    @RequiredAdmin
    public ReturnData cancel(@RequestBody MuteVo muteVo){
        adminService.cancelMute(muteVo.getUserId());
        return ReturnData.success();
    }
    
    @GetMapping("/mute/userList")
    @RequiredAdmin
    public ReturnData getMuteUser(){
        List<MuteInfo> muteUser = adminService.getMuteUser();
        return ReturnData.success(muteUser);
    }


}
